<?php

namespace App\Http\Controllers\YApi;

//use Illuminate\Http\Request;
use Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Session;
use Redirect;

use App\Models\UsersReg;
use App\Models\Book;
use App\Models\BooksPingfen;

class ReadstateController extends Controller
{

    public function readstate($readstate, $uid)
    {
        //正在读的书，想读的书，读过的书

        $pre_page = 15;
        $reads = BooksPingfen::where('read_state', $readstate)->where('uid', $uid)->orderBy('add_time', 'desc')->paginate($pre_page);

        if($reads == null)
        {
            return 0;
        }

        foreach($reads as $read)
        {
          //为了得到图书的信息
          $read['books'] = Book::where('book_id', $read->book_id)->first();
        }
        
        return $reads;
    }
    
}